package top.hzy520.common.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import top.hzy520.common.constants.Constants;
import top.hzy520.common.resp.APIResult;

/**
 * @Author: HouZeYu
 * @Description:  全局异常处理
 * @Date: Created in 22:09 2018/5/28
 */
@ControllerAdvice
@Slf4j
public class ExceptionHandlerAdvice {
     @ResponseBody
     @ExceptionHandler(Exception.class)
    public APIResult handlerException(Exception e){
         log.error(e.getMessage(),e);
         return new APIResult("系统异常请稍后再试",Constants.RESP_STATUS_INTERNAL_ERROR);
     }
    @ResponseBody
    @ExceptionHandler(YuYuBuyException.class)
    public APIResult handlerException(YuYuBuyException e){
        log.error(e.getMessage(),e);
        return new APIResult(e.getMessage(),e.getStatusCode());
    }
}
